<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${pageContext.request.contextPath}/script/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
	$(function() {
		$("#submit").click(function(e) {
			var id = $("input[name=id]").val();
			// 修改操作
			if(id != null) {
				// e.preventDefault();
				var action = "<%=request.getContextPath()%>/userService/updateUser";
				$("form").attr("action", action);
			}
		})
	});
</script>
</head>
<body>
<form action="${pageContext.request.contextPath}/userService/addUser" method="POST">
	<input type = "hidden" name = "id" value = "${user.id}" />
	<!-- 将POST请求转换为PUT请求 -->
	<input type = "hidden" name = "_method" value = "PUT"/>
	<!-- 不允许修改，用来实验@ModelAttribute，防止未在页面有数据，将空值覆盖到数据库中 -->
	<c:if test="${user.id == null}">
		userName: <input type = "text" name = "userName" value="${user.userName}"/>	<br/><br/>
	</c:if>
	password: <input type = "text" name = "password" value="${user.password}"/>	<br/><br/>
	&nbsp;&nbsp;&nbsp;sex:<input type = "text" name = "sex" value="${user.sex}"/>	<br/><br>
	&nbsp;&nbsp;email:<input type = "text" name = "email" value="${user.email}"/>	<br/><br/>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id = "submit" type = "submit" value = "submit"/>
</form>
</body>
</html>